home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / GEPOUT.C < prev    next >
C/C++ Source or Header  |  1993-08-18  |  16KB  |  596 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*           output module           */
  11. /*                                   */
  12. /*     (dynamic data is output by    */
  13. /*      the dynamic() function)      */
  14. /*                                   */
  15. /*        Zortech C/C++ 3.0 r4       */
  16. /*          MICROSOFT C 6.00         */
  17. /*          Visual C/C++ 1.0         */
  18. /*           QuickC/WIN 1.0          */
  19. /*             ULTRIX cc             */
  20. /*              GNU gcc              */
  21. /*                                   */
  22. /*   (include here compilers that    */
  23. /*   compiled GEPASI successfully)   */
  24. /*                                   */
  25. /*************************************/
  26.  
  27.  
  28. #include <stdio.h>
  29. /*#include <conio.h>*/
  30. #include <string.h>
  31. #include <math.h>
  32. #include <time.h>
  33. #include "globals.h"
  34. #include "globvar.h"
  35. #include "datab.h"
  36. #include "newton.h"
  37. #include "metconan.h"
  38. #include "lsoda.h"
  39. #include "pmu.h"
  40. #include "heapchk.h"
  41.  
  42. void report_header( FILE *ch );
  43. void out_rstoi( FILE *o );
  44. void out_rinv( FILE *o );
  45.  
  46. /* print an error message             */
  47. void out_error( int n )
  48. {
  49.  printf( "\n%s\n", errormsg[n] );
  50. }
  51.  
  52. int dat_fileovr( void )
  53. {
  54.  FILE *ch1;
  55.  
  56.  /*unlink*/
  57.  ch1 = fopen( options.datname, "wt" );             /* open output for .dat   */
  58.  if ( ch1 == NULL )                                /* fopen failed ?         */
  59.  {
  60.   if( options.debug )
  61.    printf("\n  * dat_out() - fatal error: couldn't open file %s\n", options.datname );
  62.   return -1;
  63.  }
  64.  fclose( ch1 );
  65.  return 0;
  66. }
  67.  
  68. int dat_nl( void )
  69. {
  70.  FILE *ch1;
  71.  
  72.  ch1 = fopen( options.datname, "at" );             /* open output for .dat   */
  73.  if ( ch1 == NULL )                                /* fopen failed ?         */
  74.  {
  75.   if( options.debug )
  76.    printf("\n  * dat_out() - fatal error: couldn't open file %s\n", options.datname );
  77.   return -1;
  78.  }
  79.  
  80.  fprintf(ch1,"\n");
  81.  
  82.  fclose( ch1 );
  83.  return 0;
  84. }
  85.  
  86. int dat_titles( void )
  87. {
  88.  FILE *ch1;
  89.  char *ptr;
  90.  char delim;
  91.  int i;
  92.  
  93.  switch( options.datsep )
  94.  {
  95.   case 0: delim = ' '; break;
  96.   case 1: delim = ','; break;
  97.   case 2: delim = '\t'; break;
  98.   default: delim = ' ';
  99.  }
  100.  ch1 = fopen( options.datname, "at" );             /* open output for .dat   */
  101.  if ( ch1 == NULL )                                /* fopen failed ?         */
  102.  {
  103.   if( options.debug )
  104.    printf("\n  * dat_out() - fatal error: couldn't open file %s\n", options.datname );
  105.   return -1;
  106.  }
  107.  ptr = outtit;
  108.  for(i=0;i<totsel;i++)
  109.  {
  110.   if( i ) fprintf(ch1,"%c", delim );
  111.   if( options.quotes ) fprintf(ch1,"\"" );
  112.   fprintf(ch1,"%.*s%*s", options.datwidth, ptr, options.datwidth-strlen(ptr), "" );
  113.   if( options.quotes ) fprintf(ch1,"\"" );
  114.   do{ }while( *ptr++ );
  115.  }
  116.  fprintf(ch1,"\n");
  117.  
  118.  fclose( ch1 );
  119.  return 0;
  120. }
  121.  
  122. int dat_values( void )
  123. {
  124.  FILE *ch1;
  125.  int i;
  126.  char delim;
  127.  
  128.  switch( options.datsep )
  129.  {
  130.   case 0: delim = ' '; break;
  131.   case 1: delim = ','; break;
  132.   case 2: delim = '\t'; break;
  133.   default: delim = ' ';
  134.  }
  135.  ch1 = fopen( options.datname, "at" );             /* open output for .dat   */
  136.  if ( ch1 == NULL )                                /* fopen failed ?         */
  137.  {
  138.   if( options.debug )
  139.    printf("\n  * dat_out() - fatal error: couldn't open file %s\n", options.datname );
  140.   return -1;
  141.  }
  142.  
  143.  for(i=0;i<totsel;i++)
  144.  {                                                 /* output values             */
  145.   if( i ) fprintf(ch1,"%c", delim );
  146.   fprintf(ch1,"% -*.*le", options.datwidth, options.datwidth-8, *(poutelem[i]));
  147.  }
  148.  fprintf(ch1,"\n");
  149.  
  150.  fclose( ch1 );
  151.  return 0;
  152. }
  153.  
  154. int dat_error( void )
  155. {
  156.  FILE *ch1;
  157. /* char delim;
  158.  
  159.  switch( options.datsep )
  160.  {
  161.   case 0: delim = ' '; break;
  162.   case 1: delim = ','; break;
  163.   case 2: delim = '\t'; break;
  164.   default: delim = ' ';
  165.  }*/
  166.  ch1 = fopen( options.datname, "at" );             /* open output for .dat   */
  167.  if ( ch1 == NULL )                                /* fopen failed ?         */
  168.  {
  169.   if( options.debug )
  170.    printf("\n  * dat_error() - fatal error: couldn't open file %s\n", options.datname );
  171.   return -1;
  172.  }
  173.  
  174. /* for(i=0;i<totsel;i++)
  175.  {                      */                          /* output values                */
  176. /*  if( i ) fprintf(ch1,"%c", delim );*/
  177.   /*fprintf(ch1,"% -*.*le", options.datwidth, options.datwidth-8, (double) 0 );*/
  178. /*  for(j=0;j<options.datwidth;j++) fprintf(ch1," ");
  179.  }*/
  180.  fprintf(ch1,"\n");
  181.  
  182.  fclose( ch1 );
  183.  return 0;
  184. }
  185.  
  186. void report_init( int p )
  187. {
  188.  FILE *ch1;
  189.  char mode[4];
  190.  int i,j,k;
  191.  char *ptr, auxstr[10];
  192.  
  193.  if( options.append ) strcpy( mode, "at" );
  194.  else strcpy( mode, "wt" );
  195.  strcpy( repfile, filename[p] );
  196.  fixext( repfile, '.', ".txt" );
  197.  ch1 = fopen( repfile, mode );
  198.  if( options.append ) fprintf( ch1, "\n" );            /* separate from previous    */
  199.  report_header( ch1 );
  200.  
  201.  fprintf( ch1, "\n%s\n", topname );                 /* pathway title            */
  202.                                                     /* output struct filen         */
  203.  if ( options.structan )
  204.  {
  205.   fprintf(ch1,"\nREDUCED STOICHEIOMETRY MATRIX\n");
  206.   out_rstoi( ch1 );
  207.   fprintf(ch1,"\nINVERSE OF THE REDUCTION MATRIX\n");
  208.   out_rinv( ch1 );
  209.  }
  210.                                                     /* info about moieties */
  211.  if ( depmet > 0 )
  212.  {
  213.   fprintf(ch1,"\nCONSERVATION RELATIONSHIPS\n");
  214.   for( i=indmet; i<nmetab; i++ )
  215.   {
  216.    for(j=0, k=0;j<totmet;j++)
  217.     if ( intmet[j] )
  218.      if (ld[i][j] != (float) 0)
  219.      {
  220.       sprintf(auxstr, "%s ", k ? "+" : " " );
  221.       if (ld[i][j] > (float) 1)
  222.        sprintf(auxstr, "%s %3.1f*", k ? "+" : " ", ld[i][j] );
  223.       else if (ld[i][j] < (float) -1)
  224.             sprintf(auxstr, "- %3.1f*", fabs(ld[i][j]));
  225.            else if (ld[i][j] == (float) -1)
  226.                  sprintf(auxstr, "- ");
  227.       fprintf(ch1,"%s[%s] ", auxstr, metname[j] );
  228.       k++;
  229.      }
  230.    fprintf(ch1,"= %.4lg %s\n", moiety[i], options.concu);
  231.   }
  232.  }
  233.  else
  234.   fprintf(ch1,"\nNO CONSERVATION RELATIONSHIPS\n");
  235.  
  236.  fprintf(ch1,"\nKINETIC PARAMETERS\n");             /* output kinetic p.        */
  237.  for( i=0; i<nsteps; i++ )
  238.  {
  239.   fprintf(ch1,"%s (%s)\n",stepname[i], ktype[kinetype[i]].descr);
  240.   ptr = ktype[kinetype[i]].constnam;
  241.   for(j=0;j<(int)ktype[kinetype[i]].nconst; j++)
  242.   {
  243.    fprintf(ch1," %s = % .4le\n", ptr, params[i][j] );
  244.    do{ } while( *(ptr++) );
  245.   }
  246.  }
  247.  
  248.  fclose(ch1);
  249. }
  250.  
  251. void report_dyn( void )
  252. {
  253.  FILE *ch1;
  254.  int i;
  255.  
  256.  ch1 = fopen( repfile, "at" );
  257.  
  258.  /* output concentrations    */
  259.  fprintf( ch1, "\nRESULTS OF INTEGRATION (after %.2le %s)\n", endtime, options.timeu );
  260.  for( i=0; i<totmet; i++ )
  261.   fprintf(ch1,"[%s] initial = % .6le %s, final = % .6le %s%s\n",
  262.               metname[i], x0[i], options.concu, x[i],
  263.               options.concu, x[i] >= 0 ? "" : " BOGUS!");
  264.  
  265.  /* output fluxes            */
  266.  for( i=0; i<nsteps; i++ )
  267.   fprintf( ch1, "J(%s) = % .6le %s/%s\n", stepname[i], flux[i], options.concu, options.timeu );
  268.  
  269.  fclose(ch1);
  270. }
  271.  
  272. void report_ss( int diverge, int ccfs )
  273. {
  274.  FILE *ch1;
  275.  int i,j,k;
  276.  double moi;
  277.  char auxstr[10];
  278.  
  279.  ch1 = fopen( repfile, "at" );
  280.  
  281.  if( diverge == N_OK )
  282.  {
  283.   /* check if steady state is an equilibrium */
  284.   if ( equilibrium() )
  285.    fprintf(ch1,"\nEQUILIBRIUM SOLUTION\n");
  286.   else
  287.    fprintf(ch1,"\nSTEADY STATE SOLUTION\n");
  288.  
  289.   /* concentrations    */
  290.   for( i=0; i<totmet; i++ )
  291.   {
  292.    fprintf(ch1,"[%s] = % .6le %s, tt = % .6le %s, rate = % .3le %s/%s",
  293.                metname[i], xss[i], options.concu, tt[i], options.timeu,
  294.                rate[i], options.concu, options.timeu);
  295.    if( xss[i] < 0 ) fprintf(ch1," BOGUS!");
  296.    fprintf(ch1,"\n");
  297.   }
  298.  
  299.   /* mass conservation    */
  300.   if ( depmet > 0 )
  301.   {
  302.    for( i=indmet; i<nmetab; i++ )
  303.    {
  304.     moi = 0;
  305.     for(j=0, k=0;j<totmet;j++)
  306.      if ( intmet[j] )
  307.       if (ld[i][j] != (float) 0)
  308.       {
  309.        moi += (double)ld[i][j] * xss[j];
  310.        sprintf(auxstr, "%s ", k ? "+" : " " );
  311.        if (ld[i][j] > (float) 1)
  312.         sprintf(auxstr, "%s